<template>
  <div >
    <el-table
      :data="tableData"
      style="width: 100%">
      <el-table-column
        prop="id"
        label="id"
        width="180">
      </el-table-column>
      <el-table-column
        prop="name"
        label="姓名"
        width="180">
      </el-table-column>
      <el-table-column
        prop="address"
        label="地址">
      </el-table-column>
      <el-table-column
        prop="phone"
        label="电话">
      </el-table-column>
      <el-table-column
        prop="email"
        label="邮箱">
      </el-table-column>
    </el-table>

    <el-pagination
      background
      layout="prev, pager, next"
      :total="total"
      align="right"
      :current-page="pagesize"
      :page-size="currentPage"
      @current-change="goPage"
    >
    </el-pagination>
  </div>
</template>

<script>
export default {
  name: 'user',
  data () {
    return {
      tableData: [],
      totals:0,
      currentPage: 1,
      pagesize:5
    }
  },
  methods:{
    getUsers() {
      // 发送axios请求 获取后端数据
      let param = {"currentPage":this.currentPage,"pageSize":this.pagesize}
      this.$http.post("/user/list",param)
      .then(result=>{
          this.tableData = result.data.data;
          this.total = result.data.totals
      }).catch(result=>{
        alert("请求失败！")
      })
    },
    goPage(currentPage){
      this.currentPage = currentPage;
      this.getUsers();
    }

  },
  mounted() {
    this.getUsers();
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>

</style>
